package com.systemic.service.impl;

import com.systemic.dto.LoginUserDto;
import com.systemic.service.UserService;
import com.systemic.mapper.UserMapper;
import com.systemic.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName: UserServiceImpl
 * @Description:
 * @Author:
 * @CreateTime: 2023-12-26 20:09
 * @Version:
 **/
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User findByAccount(String account) {
        return userMapper.findByAccount(account);
    }

    /**
     * 获取用户id和账号，提供给websocket
     * @param uid
     * @return
     */
    @Override
    public LoginUserDto findById(Integer uid) {
        User user = userMapper.findById(uid);
        LoginUserDto loginUserDto = new LoginUserDto();
        if (user!=null){
            loginUserDto.setUid(user.getUid());
            loginUserDto.setAccount(user.getAccount());
        }
        return loginUserDto;
    }

    /**
     * 新增用户
     * @param user
     */
    @Override
    public void addUser(User user) {
        Date date = new Date();
        user.setGmtCreate(date);
        user.setGmtModified(date);
        userMapper.insert(user);
    }

    @Override
    public User findByAccountAndPassword(String account, String password) {
        User user = userMapper.findByAccountAndPassword(account, password);
        if (user==null){
            System.out.println("没有查询到用户");
        }
        return user;
    }


}
